package com.gxuwz.service.impl;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import com.gxuwz.dao.IUserInfoDao;
import com.gxuwz.entity.SysUser;
import com.gxuwz.service.IUserInfoService;

@Service("userInfoService")
public class UserInfoServiceImpl implements IUserInfoService {

	@Resource(name = "userInfoDao")
	private IUserInfoDao userInfoDao;

	@Override
	public UserDetails loadUserByUsername(String username)
			throws UsernameNotFoundException {
		System.out.println("service login...");
		if (StringUtils.isNotEmpty(username)) {
			SysUser user = userInfoDao.getUserByName(username.trim());
			if (user != null) {
				System.out.println("用户名:"+user.getUsername()+" "+"密码："+user.getPassword());
				return user;
			}
		}
		throw new UsernameNotFoundException(
				"Can't not find user while username is '" + username.trim()
						+ "'");
	}

}
